<!--
 * @Author: 噜噜雯雯 2199987619@qq.com
 * @Date: 2025-05-30 15:00:30
 * @LastEditors: 噜噜雯雯 2199987619@qq.com
 * @LastEditTime: 2025-09-28 15:38:29
 * @FilePath: \linePatrol\vue-element-plus-admin\src\views\Authorization\Dictionary\components\EditDictType.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<script setup lang="tsx">
import { Form, FormSchema } from '@/components/Form'
import { useForm } from '@/hooks/web/useForm'
import { ScheduleSendTaskDetailType } from '@/api/linePatrol/type'
import { computed, PropType, ref, watch } from 'vue'
import { usePatrolGroupStore } from '@/store/modules/PlanGroupStore'
import { rules, schema } from './PublicTableData'
const GroupStore = usePatrolGroupStore()
const props = defineProps({
  currentRow: {
    type: Object as PropType<Nullable<ScheduleSendTaskDetailType>>,
    default: () => null
  },
  DisabledForm: {
    type: Object as PropType<boolean>,
    default: () => null
  }
})

const { formRegister, formMethods } = useForm()
const { setValues, getFormData, getElFormExpose } = formMethods
watch(
  () => props.currentRow,
  (currentRow) => {
    if (!currentRow) return
    setValues(currentRow)
  },
  {
    deep: true,
    immediate: true
  }
)
const FacTaskList = computed(() => {
  return GroupStore.getFacTaskListAll
}) //任务组名称列表
// 生成新数组
const newItem: FormSchema = {
  field: 'taskId',
  label: '任务组名称',
  component: 'Select',
  colProps: {
    span: 15
  },
  componentProps: {
    options: FacTaskList.value.map((item: any) => {
      if (item.taskName) {
        return {
          label: `任务组名称：${item.taskName}`,
          value: item.id
        }
      } else {
        return {
          label: `任务组名称：${item.groupName}`,
          value: item.id
        }
      }
    })
  }
}
const newArray = ref<FormSchema[]>([...schema.slice(0, 1), newItem, ...schema.slice(1)])
const submit = async () => {
  const elForm = await getElFormExpose()
  const valid = await elForm?.validate().catch((err) => {
    console.log(err)
  })
  if (valid) {
    const formData = await getFormData()
    formData['planType'] = GroupStore.activeName
    return formData
  }
}
defineExpose({
  submit
})
</script>
<template>
  <Form :disabled="props.DisabledForm" :schema="newArray" @register="formRegister" :rules="rules" />
</template>
<style scoped>
/* ::v-deep是vue3提供的深度选择器，.el-form-item__label是element-plus官方定义的类 */
.FormHead {
  /* font-size: 18px; */
  font-weight: 600;
}
:deep(.el-col){
  margin: 5px 0;
}
:deep(.el-form-item__label) {
  display: inline-block !important;
}
.label {
  font-size: 15px;
  font-weight: 800;
}
</style>
@/store/modules/PlanGroupApi
